package com.google.code.tretris.rendering;

import java.util.concurrent.ConcurrentHashMap;

import javax.microedition.khronos.opengles.GL10;

import com.google.code.tretris.events.UpdateBoardEvent;

public class Scene extends MVComplexObject {

	private ConcurrentHashMap<String, Grid> grids = new ConcurrentHashMap<String, Grid>();

	public Scene(final String clientID) {
		addNewPlayer(clientID);
	}


	public boolean contains(final Grid grid) {
		return grids.contains(grid);
	}

	public boolean contains(final String clientID) {
		return grids.containsKey(clientID);
	}

	public void render(final GL10 gl) {
		for (Grid grid : grids.values()) {
			grid.render(gl);
		}
	}

	public void update(final UpdateBoardEvent e) {
		grids.get(e.getClientID()).update(e);
	}
	
	public boolean doesNotContainPlayer(String clientID) {
		return !contains(clientID);
	}
	

	public Grid addNewPlayer(String clientID) {
		Grid grid = new Grid.Builder().clientId(clientID).shape(new Shape())
				.build();
		return grids.put(clientID, grid);
	}
}
